package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import com.fr.report.script.core.FunctionHelper;

public class INT extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    Object localObject = paramArrayOfObject[0];
    if ((localObject != null) && (!(localObject instanceof Number)))
    {
      localObject = localObject.toString();
      try
      {
        int i = Integer.parseInt((String)localObject);
        localObject = new Integer(i);
      }
      catch (Exception localException1)
      {
        try
        {
          double d = Double.parseDouble((String)localObject);
          localObject = new Double(d);
        }
        catch (Exception localException2)
        {
          return Primitive.ERROR_VALUE;
        }
      }
    }
    if (localObject != null)
      return FunctionHelper.parsePrimitiveDouble(((Number)localObject).longValue());
    return Primitive.ERROR_NAME;
  }

  public Function.Type getType()
  {
    return Function.MATH;
  }

  public String getCN()
  {
    return "INT(number): 返回数字下舍入（数值减小的方向）后最接近的整数值。\nNumber:需要下舍入为整数的实数。\n示例:\nINT(4.8)等于4。\nINT(-4.8)等于-5。\nINT(4.3)等于4。\nINT(-4.3)等于-5。\n公式INT(A1)将返回A1单元格中的一个正实数的整数数部分。";
  }

  public String getEN()
  {
    return "INT(number): Rounds a number down to the nearest integer.\n\nExample:\n   INT(4.8) = 4。\n   INT(-4.8) = -5。\n   INT(4.3) = 4。\n   INT(-4.3) = -5。\n   Formula INT(A1) returns integer of the real number of A1 Cell.";
  }
}